// pages/timetable/timetable.js
import http from '../../utils/http'
Page({

  /**
   * 页面的初始数据
   */
  data: {
    lessons: [{
      "lessonId": 1,
      "lesson": "第一节"
    },
    {
      "lessonId": 2,
      "lesson": "第二节"
    },
    {
      "lessonId": 3,
      "lesson": "第三节"
    },
    {
      "lessonId": 4,
      "lesson": "第四节"
    },
    {
      "lessonId": 5,
      "lesson": "第五节"
    }, {
      "lessonId": 6,
      "lesson": "第六节"
    },
    {
      "lessonId": 7,
      "lesson": "第七节"
    },
    {
      "lessonId": 8,
      "lesson": "第八节"
    },
    {
      "lessonId": 9,
      "lesson": "第九节"
    },
    {
      "lessonId": 10,
      "lesson": "第十节"
    }
    ],
    courseList: [{
      "day": "周一",
      "list": [
        {
          "lessonId": 1,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 2,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 3,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 4,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 5,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 6,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 7,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 8,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 9,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 10,
          "courseName": "",
          "location": ""
        }
      ]
    },
    {
      "day": "周二",
      "list": [
        {
          "lessonId": 1,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 2,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 3,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 4,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 5,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 6,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 7,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 8,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 9,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 10,
          "courseName": "",
          "location": ""
        }
      ]
    },
    {
      "day": "周三",
      "list": [
        {
          "lessonId": 1,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 2,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 3,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 4,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 5,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 6,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 7,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 8,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 9,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 10,
          "courseName": "",
          "location": ""
        }
      ]
    },
    {
      "day": "周四",
      "list": [
        {
          "lessonId": 1,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 2,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 3,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 4,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 5,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 6,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 7,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 8,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 9,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 10,
          "courseName": "",
          "location": ""
        }
      ]
    },
    {
      "day": "周五",
      "list": [
        {
          "lessonId": 1,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 2,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 3,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 4,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 5,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 6,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 7,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 8,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 9,
          "courseName": "",
          "location": ""
        },
        {
          "lessonId": 10,
          "courseName": "",
          "location": ""
        }
      ]
    }
    ]
  },
  getTimetable() {
    http({
      url: '/student/timetable',
      headers: {
        'cookie': wx.getStorageSync('cookie').toString()
      }
    }).then(res => {
      // console.log(res);
      res.data.forEach(item => {
        let timeArr = item.time.split('-')
        for (let i = timeArr[1] - 1; i < (timeArr[2] - 0) + (timeArr[1] - 1); i++) {
          this.setData({
            ['courseList[' + (timeArr[0] - 1) + '].list[' + i + '].courseName']: item.courseName,
            ['courseList[' + (timeArr[0] - 1) + '].list[' + i + '].location']: item.location
          })
        }
      })
    })
  },
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {
    this.getTimetable()
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {

  }
})